package  
{
	import flash.net.SharedObject;
	/**
	 * ...
	 * @author Haxx
	 */
	public class PlayerRecords 
	{
		public static var highestFloor:int = 0;
		
		public static var enemiesKilled:int = 0;
		public static var timesReincarnated:int = 0;
		
		
		public function PlayerRecords() 
		{
			
		}
		
		public static function saveData():void
		{
			try
			{
				var mySharedObject:SharedObject = SharedObject.getLocal("records");
				mySharedObject.data.playerCoins = PlayerUpgrades.playerCoins;
				mySharedObject.data.elevatorSpeedLevel = PlayerUpgrades.lvlElevatorSpeed;
				mySharedObject.data.lifeLevel = PlayerUpgrades.lvlMaxLife;
				mySharedObject.data.timesReincarnated = PlayerRecords.timesReincarnated;
				mySharedObject.flush();
				trace("PlayRecords.saveData: Save data successful");
			}catch (e:Error) { trace("PlayRecords.saveData ERROR SAVING DATA"); }
		}
		
		public static function loadData():void
		{
			
			try
			{
				var mySharedObject:SharedObject = SharedObject.getLocal("records");
				
				if (mySharedObject == null)
				{
					trace("PlayRecords.loadData(): NO SAVE DATA FOUND");
					return;
				}
				else
				{
					trace("PlayRecords.loadData(): LOADING SAVE DATA");
					PlayerUpgrades.playerCoins = mySharedObject.data.playerCoins;
					PlayerUpgrades.lvlElevatorSpeed = mySharedObject.data.elevatorSpeedLevel;
					PlayerUpgrades.lvlMaxLife = mySharedObject.data.lifeLevel;
					PlayerRecords.timesReincarnated = mySharedObject.data.timesReincarnated;
					
					if (PlayerUpgrades.lvlElevatorSpeed <= 0) PlayerUpgrades.lvlElevatorSpeed = 1;
					if (PlayerUpgrades.lvlMaxLife <= 0) PlayerUpgrades.lvlMaxLife = 1;
				}
			}catch (e:Error) { trace("PlayRecords.loadData ERROR LOADING DATA"); }
		}
		
		public static function deleteData():void
		{
			try
			{
				var mySharedObject:SharedObject = SharedObject.getLocal("records");
				
				if (mySharedObject == null)
				{
					trace("PlayRecords.loadData(): NO SAVE DATA FOUND");
					return;
				}
				else
				{
					trace("PlayRecords.loadData(): DELETING SAVE DATA");
					mySharedObject.clear();
					PlayerUpgrades.playerCoins = 0;
					PlayerUpgrades.lvlElevatorSpeed = 1;
					PlayerUpgrades.lvlMaxLife = 1;
					PlayerRecords.timesReincarnated = 0;
				}
			}catch (e:Error) { trace("PlayRecords.loadData ERROR DELETING DATA"); }
		}
	}

}